<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery.min.js"></script>

</head>

<body>
    <button id="btn1">get</button>
    <button id="btn2">post</button>
    <button id="btn3">jsonp</button>
    <script>
        function fn(data) {
            console.log('我被调用了');
            console.log(data);
        }
        $(function() {
            $('#btn1').on('click', function() {
                $.ajax({
                    type: 'get',
                    url: 'http://127.0.0.1/api/get',
                    data: {
                        name: 'zls',
                        age: 1
                    },

                    success: function(res) {
                        console.log(res);
                    }
                });
                console.log(11);
            })
            $('#btn2').on('click', function() {
                $.ajax({
                    type: 'post',
                    url: 'http://127.0.0.1/api/post',
                    data: {
                        name: 'zks',
                        age: 122
                    },
                    success: function(res) {
                        console.log(res);
                    }
                })
            });

            function getuser(data) {
                console.log(data);
            }
            $('#btn3').on('click', function() {
                // var myscript = document.createElement('script');
                // myscript.src = 'http://127.0.0.1/api/jsonp?callback=fn'
                // document.body.appendChild(myscript);
                $.ajax({
                    type: 'get',
                    dataType: 'jsonp ',
                    //发送到服务端参数名称
                    jsonp: 'callback',
                    //自定义回调函数名称
                    jsonpCallback: 'fn',
                    url: 'http://127.0.0.1/api/jsonp',
                    dataType: 'jsonp',
                    success: function(res) {
                        console.log(res);
                    }
                })
            })
        })
    </script>
</body>

</html>